from multiprocessing import Process
from time import sleep
import os

def sub_process(name):
    print(f'执行子进程pid:{os.getpid()}，父进程pid：{os.getppid()}======{name}')
    sleep(1)

def sub_process2(age):
    print(f'执行子进程pid:{os.getpid()}，父进程pid：{os.getppid()}======{age}')
    sleep(1)

if __name__ == '__main__':
    print('父进程开始')

    for i in range(3):
        p1 = Process(target=sub_process, args=('anne',))
        p2 = Process(target=sub_process2, args=(20,))
        print('创建子进程。。。')
        p1.start()
        p2.start()
        print(p1.name, p1.pid, '是否执行中：', p1.is_alive())
        print(p2.name, p2.pid, '是否执行中：', p2.is_alive())

        p1.join() # 阻塞创建，等待p1执行结束
        p2.join() # 等待p2执行结束
        # 此处 is_alive 为false

    print('主进程结束')
